package org.hive.testserver.domain.util;

import org.apache.commons.lang.StringUtils;

public class IdParser {

	private String[] components;
	
	public static final char ID_COMPONENT_SEPARATOR = ':';
	
	public IdParser(String fullId) {
		super();
		components = StringUtils.split(StringUtils.defaultString(fullId), ID_COMPONENT_SEPARATOR);
	}
	
	public String component(int index) {
		if (index < components.length) {
			return StringUtils.trim(components[index]);
		} else {
			return StringUtils.EMPTY;
		}
	}
	
	public static class RunIdParser {
		private IdParser parser;

		public RunIdParser(String runId) {
			super();
			parser = new IdParser(runId);
		}
		
		public String projectName() {
			return parser.component(0);
		}
		
		public String runName() {
			return parser.component(1);
		}
	}
}
